<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();//获得项目的根目录，上下文路径
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>超市账单管理系统</title>
<link rel="stylesheet" href="css/public.css" />
<link rel="stylesheet" href="css/style.css" />
<script src="js/jquery.js"></script>
<script type="text/javascript">

//2、测试电话号码是否唯一$.post()
$(function(){
	$("#proPhone").blur(function () {
		testPhone($(this));
	});
});
function testPhone(t){
	//1
	var v= t.val();
	var sp = t.next();
	var div = t.parent();
	sp.empty();
	$.ajaxSettings.async=false;//设置ajax同步
	var flag = false ;
	//2
	$.post(
		"testPhone.ht",
		{
			proPhone :v
		},
		function(res){
			console.log(res);
			flag = res.result;
			if(!flag){
				sp.html(v+"不可用");
				div.removeClass("ok").addClass("error");
			}else{
				sp.html(v+"可用");
				div.removeClass("error").addClass("ok");
			}
		},
		"json"	
	);
	$.ajaxSettings.async=true;//设置ajax异步
	//3 
	return flag;
}

//3、测试供应商电话是否唯一$.post()
$(function(){
	$("#proFax").blur(function () {
		testProFax($(this));
	});
});
function testProFax(t){
	//1
	var v= t.val();
	var sp = t.next();
	var div = t.parent();
	sp.empty();
	$.ajaxSettings.async=false;//设置ajax同步
	var flag = false ;
	//2
	$.post(
		"testProFax.ht",
		{
			proFax :v
		},
		function(res){
			console.log(res);
			flag = res.result;
			if(!flag){
				sp.html(v+"不可用");
				div.removeClass("ok").addClass("error");
			}else{
				sp.html(v+"可用");
				div.removeClass("error").addClass("ok");
			}
		},
		"json"	
	);
	$.ajaxSettings.async=true;//设置ajax异步
	//3 
	return flag; 
}

$(function() {
	$("#proCode").blur(function() {
		testproCode($(this));
	});
	$("#proName").blur(function() {
		testproName($(this));
	});
	$("#proPhone").blur(function() {
		testproPhone($(this));
	});
	$("#proContact").blur(function() {
		testproContact($(this));
	});
	$("#proAddress").blur(function() {
		testproAddress($(this));
	});
	$("#proDesc").blur(function() {
		testproDesc($(this));
	});
	$("#proFax").blur(function() {
		testproFax($(this));
	});
	$("#addPro").submit(
			function() {
				var flag = testproCode($("#proCode"))
						& testproName($("#proName"))
						& testproPhone($("#proPhone"))
						& testproContact($("#proContact"))
						& testproAddress($("#proAddress"))
						& testproDesc($("#proDesc"))
						& testproFax($("#proFax"));

				if (flag == 0) {
					return false;
				}
				return true;
			});
	function testproCode(t) {
		var v = t.val();
		var sp = t.next();
		var div = t.parent();
		if (v.length == 0) {
			sp.html("供应商编码不能为空！！！");
			div.removeClass("ok").addClass("error");
			return false;
		} else {
			sp.html("&radic;");
			div.removeClass("error").addClass("ok");
			return true;
		}
	}
	function testproDesc(t) {
		var v = t.val();
		var sp = t.next();
		var div = t.parent();
		if (v.length == 0) {
			sp.html("供应商描述不能为空！！！");
			div.removeClass("ok").addClass("error");
			return false;
		} else {
			sp.html("&radic;");
			div.removeClass("error").addClass("ok");
			return true;
		}
	}
	function testproName(t) {
		var v = t.val();
		var sp = t.next();
		var div = t.parent();
		if (v.length == 0) {
			sp.html("供应商名称不能为空！！！");
			div.removeClass("ok").addClass("error");
			return false;
		} else {
			sp.html("&radic;");
			div.removeClass("error").addClass("ok");
			return true;
		}
	}
	function testproPhone(t) {
		var v = t.val();
		var sp = t.next();
		var div = t.parent();
		if (v.length == 0) {
			sp.html("手机号码不能为空！！！");
			div.removeClass("ok").addClass("error");
			return false;
		} else {
			sp.html("&radic;");
			div.removeClass("error").addClass("ok");
			return true;
		}
	}
	function testproContact(t) {
		var v = t.val();
		var sp = t.next();
		var div = t.parent();
		if (v.length == 0) {
			sp.html("负责人不能为空！！！");
			div.removeClass("ok").addClass("error");
			return false;
		} else {
			sp.html("&radic;");
			div.removeClass("error").addClass("ok");
			return true;
		}
	}
	function testproAddress(t) {
		var v = t.val();
		var sp = t.next();
		var div = t.parent();
		if (v.length == 0) {
			sp.html("地址不能为空！！！");
			div.removeClass("ok").addClass("error");
			return false;
		} else {
			sp.html("&radic;");
			div.removeClass("error").addClass("ok");
			return true;
		}
	}
	function testproFax(t) {
		var v = t.val();
		var sp = t.next();
		var div = t.parent();
		if (v.length == 0) {
			sp.html("电话不能为空！！！");
			div.removeClass("ok").addClass("error");
			return false;
		} else {
			sp.html("&radic;");
			div.removeClass("error").addClass("ok");
			return true;
		}
	}
});
</script>
</head>
<body>
	<!--头部-->
	<header class="publicHeader">
		<h1>超市账单管理系统</h1>
		<div class="publicHeaderR">
			<p>
				<span>下午好！</span>
				<span style="color: #fff21b"> ${USER_LOGIN.userName }</span>
				, 欢迎你！
			</p>
			<a href="logOut.html">退出</a>
		</div>
	</header>
	<!--时间-->
	<section class="publicTime">
		<span id="time">2015年1月1日 11:11 星期一</span>
		<a href="#">温馨提示：为了能正常浏览，请使用高版本浏览器！（IE10+）</a>
	</section>
	<!--主体内容-->
	<section class="publicMian ">
		<div class="left">
			<h2 class="leftH2">
				<span class="span1"></span>
				功能列表
				<span></span>
			</h2>
			<nav>
				<ul class="list">
					<li><a href="billList.html">账单管理</a></li>
					<li id="active"><a href="providerList.ht">供应商管理</a></li>
					<li ><a href="userList.html">用户管理</a></li>
					<li><a href="roleList.html">角色管理</a></li>
					<li><a href="password.html">密码修改</a></li>
					 <li><a href="goodsList.du">商品购买</a></li>
					<li><a href="logOut.html">退出系统</a></li>
				</ul>
			</nav>
		</div>
		<div class="right">
			<div class="location">
				<strong>你现在所在的位置是:</strong>
				<span>供应商管理页面 >> 供应商添加页面</span>
			</div>
			<div class="providerAdd">
				<form action="proUpdate.ht?id=${PRO.id}" method="post" >
					<!--div的class 为error是验证错误，ok是验证成功-->
					<div class="">
						<label for="proCode">供应商编码：</label>
						<span>${PRO.proCode}</span>
					</div>
					<div>
						<label for="proName">供应商名称：</label>
						<span>${PRO.proName}</span>
					</div>
					<div>
						<label for="proDesc">供应商描述：</label>
						<input type="text" name="proDesc" id="proDesc" value="${PRO.proDesc}" onkeyup="value=value.replace(/(^\s*)|(\s*$)/g,'')"/>
						<span></span>
					</div>
					<div>
						<label for="proContact">负责人：</label>
						<input type="text" name="proContact" id="proContact" value="${PRO.proContact}" onkeyup="value=value.replace(/(^\s*)|(\s*$)/g,'')"/>
						<span></span>
					</div>
					<div>
						<label for="proPhone">手机号码：</label>
						<input type="text" name="proPhone" id="proPhone" value="${PRO.proPhone}" onkeyup="value=value.replace(/(^\s*)|(\s*$)/g,'')"/>
						<span>*</span>
					</div>
					<div>
						<label for="proAddress">地址：</label>
						<input type="text" name="proAddress" id="proAddress" value="${PRO.proAddress}" onkeyup="value=value.replace(/(^\s*)|(\s*$)/g,'')"/>
						<span>*</span>
					</div>
					<div>
						<label for="proFax">电话：</label>
						<input type="text" name="proFax" id="proFax" value="${PRO.proFax}" onkeyup="value=value.replace(/(^\s*)|(\s*$)/g,'')"/>
						<span>*</span>
					</div>
					<div class="providerAddBtn">
						<input type="submit" style="padding:0px;" value="提交"/>
						<input type="reset"  style="padding:0px;width:100px;font-size:14px;"/>
					</div>
				</form>
			</div>
		</div>
	</section>
	<footer class="footer"> 版权归北大青鸟 </footer>
	<script src="js/time.js"></script>
</body>
</html>